create view dbo.vWaitStateHistory as
select distinct 
	a.[DatabaseID],
	a.[SessionID], 
	b.[Name] 'Wait_Type',
	isnull(c.[Requests],0) 'Requests',
	isnull(c.[Wait_Time],0) 'Wait_Time',
	isnull(c.[Signal_Wait_Time],0) 'Signal_Wait_Time',
	a.[ScanStart] 'CreateDate'
from
	ScanHistory a
		cross join WaitStates b
		left outer join WaitStateHistory c on c.[sessionid]=a.[sessionid]
											  and c.[Wait_Type]=b.[name]
where
	a.[objecttype]='SQLAutoDocLib.WaitStateLog'